home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc™ Source Code / Messaging / OSL / OSLInit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  8.0 KB  |  289 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        OSLInit.c
  3.  
  4.     Contains:    Initialization routines for the OSL
  5.  
  6.     Owned by:    Nick Pilch
  7.  
  8.     Copyright:    © 1992 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <3>      6/6/96    jpa        T10020: Eliminated warning by adding a
  13.                                     crucial "&" in iAEObjectInit.
  14.          <2>     1/15/96    TJ        Cleaned Up
  15.          <7>     7/27/95    eeh        1204615: remove Nick's DebugStr
  16.          <6>     6/27/95    NP        1262792: new version of OSLObjectInit
  17.          <5>      5/3/95    NP        1211084: Remove 5$
  18.          <4>     1/12/95    jpa        Don't use obsolete Toolbox names [1211211]
  19.          <3>     9/29/94    RA        1189812: Mods for 68K build.
  20.          <2>     8/19/94    NP        1181622: Ownership fix.
  21.          <7>      5/2/94    eeh        bug #1160654: various PPC native changes
  22.          <6>      2/7/94    NP        Tiger Team doings.
  23.          <5>     11/5/93    NP        Change in function declaration to satisfy
  24.                                     MPW C.
  25.          <4>     11/2/93    NP        Move pascal keyword.
  26.          <3>    10/11/93    NP        Added DebugStr.
  27.          <2>     7/28/93    NP        Mods for new token type, OSLToken.
  28.          <1>     7/21/93    NP        first checked in
  29.  
  30.     To Do:
  31.     In Progress:
  32.         
  33. */
  34.  
  35. /*                                            
  36.     ©Apple Computer, Inc.  1992         
  37.           All Rights Reserved.                
  38.     Author: Eric House
  39.                                             */
  40.  
  41. #ifndef _OSLPRIV_
  42. #include "OSLPriv.h"
  43. #endif
  44.  
  45. #pragma segment AEObjSuppt
  46.  
  47. //pascal OSErr
  48. //AEObjectInit(void);
  49. pascal OSErr
  50. iAESetObjectCallbacks( OSLCompareUPP myCompareProc, OSLCountUPP myCountProc,
  51.         OSLDisposeTokenUPP myDisposeTokenProc,
  52.         OSLGetMarkTokenUPP myGetMarkTokenProc, OSLMarkUPP myMarkProc,
  53.         OSLAdjustMarksUPP myAdjustMarksProc,
  54.         OSLGetErrDescUPP reserved );
  55.  
  56. /* WARNING: this struct depends on the current implementation of the hash
  57.  * manager staying the same.  If it changes, this will break! */
  58.  
  59. typedef struct  {        
  60.         long someLongField ;            
  61.         long hashTableSize ;                
  62.     } hashTableRec, *hashTableRecP, **hashTableRecH ;
  63.  
  64. static Boolean IsValidHashTable( HHand ahp )
  65. {
  66.     long hSize ;
  67.     Boolean retVal = false ;            /* the safe thing to assume */
  68.  
  69.     hSize = GetHandleSize( (Handle)ahp ) ;
  70.     if ( (MemError() == noErr)
  71.             && (hSize == (*(hashTableRecH)ahp)->hashTableSize) )
  72.         retVal = true ;
  73.     return retVal;
  74. }
  75.  
  76.  
  77. #pragma segment AEObjGlue
  78. //#if GENERATINGCFM
  79. void ShouldNotBeHere();
  80. void ShouldNotBeHere()
  81. {
  82.     DebugStr( "\pYou shouldn't be here" ) ;
  83. }
  84. //#endif
  85.  
  86.     /*Initializes the hash table and other goodies required by the object
  87.         resolution stuff */
  88. pascal OSErr
  89. iAEObjectInit(OSLContext* context)
  90. {
  91.  
  92.     GlobalRecHandle appGlobal ;
  93.     GlobalRecHandle sysGlobal ;
  94.     OSErr out ;
  95.     long ignore ;
  96.     HHand tempH ;                /* added to avoid Hlock and Unlock around AENewHashTable calls */
  97.     OSLToken nullDesc ;
  98.     OSErr err;
  99.  
  100.     err = AddContextToTopOfStack(context);
  101.         if (err) return err;
  102.  
  103.     // NOTICE BOGUS PROCPTR HERE FOR NOW. ONLY HERE BECAUSE OF COMMENT BELOW,
  104.     //    "inits app global"
  105.  
  106. #if GENERATINGCFM
  107.     out = AEInstallSpecialHandler( keySelectProc,
  108.             (UniversalProcPtr)ShouldNotBeHere, false ) ;
  109. #else
  110. //    out = AEInstallSpecialHandler( keySelectProc,
  111. //            (UniversalProcPtr)SelectorDispatch, false ) ;    /* inits app global */
  112.     out = AEInstallSpecialHandler( keySelectProc,
  113.             (UniversalProcPtr)ShouldNotBeHere, false ) ;
  114. #endif
  115.     appGlobal = GetGlobalRef();
  116.  
  117.     /* if it is not already inited, we must force the AEM to init the system global */
  118.     sysGlobal = GetSysGlobal() ;
  119.     if ( sysGlobal == NULL ) 
  120.     {
  121.         IgnoreOSErr( AEGetEventHandler( 'go b', 'ears', (AEEventHandlerUPP *)&ignore,
  122.                 &ignore, true ) ) ;
  123.         sysGlobal = GetSysGlobal() ;
  124.     }
  125.      
  126.     if ( out == noErr )
  127.         if ( ((*appGlobal)->accessorHashTable == nil)
  128.                 || !IsValidHashTable( (*appGlobal)->accessorHashTable ) )
  129.         {
  130.             out = AENewHashTable( kInitialHashTableSize, 8, 8, NULL, false, &tempH );
  131.             if ( out == noErr )
  132.                 (*appGlobal)->accessorHashTable = tempH ;
  133.         }
  134.  
  135.     if ( ((*sysGlobal)->accessorHashTable == nil) && (out == noErr) )
  136. #ifdef _MPWFIX_
  137.     if ( ((*sysGlobal)->AccessorHashTable == nil )
  138.                     || !IsValidHashTable( (*sysGlobal)->AccessorHashTable ) 
  139. #endif
  140.         {
  141.     //        out = AENewHashTable( kInitialHashTableSize, 8, 8, NULL, true, &tempH ) ;
  142.             if ( out == noErr )
  143.                 (*sysGlobal)->accessorHashTable = tempH ; 
  144.         }
  145.  
  146. // <eeh> removed 7/93 as part of PPC port; will call the coercion directly rather
  147. // than via the AEM.
  148. //    if ( out == noErr )
  149. //        out = AEInstallCoercionHandler( typeWhoseDescriptor, typeWhoseDescriptor,
  150. //                              (EventHandlerUPP)MakeExternalWhose, 0, true, false ) ;
  151.  
  152.     MakeNullToken( &nullDesc ) ;                /* 3/11/92 */
  153.     SetExmn( &nullDesc ) ;
  154.  
  155.     return out ;
  156. }
  157.  
  158. #pragma segment AEObjSuppt
  159.  
  160. OSErr MakeExternalWhose( const AEDesc* desc, AEDesc *result )
  161. {
  162.  
  163.     AEDesc dWhoseRange, dRangeStart ;
  164.     AERecord dWhoseRecord,    dWhoseRangeRec ;
  165.     IndexRecord  index ;
  166.     DescType  typeCode ;
  167.     Size  actualSize ;
  168.     OSErr err ;
  169.  
  170. //    DebugStr("\pOSLInit.MakeExternalWhose: Inside MakeExternalWhose. Call Nick.");
  171.  
  172.     err = AECoerceDesc( desc, typeAERecord, &dWhoseRecord ) ;
  173.     if ( err != noErr ) goto a ;
  174.  
  175.     err = AEGetKeyPtr( &dWhoseRecord, keyAEIndex, typeWhoseRangeInternal, &typeCode,
  176.                              (Ptr)&index, sizeof(index), &actualSize ) ;
  177.     if ( err != noErr ) goto b ;
  178.     
  179.     err = AECreateDesc( index.startCase, (Ptr)&index.startValue, SizeOf(index.startValue),
  180.             &dRangeStart ) ;
  181.     if ( err != noErr ) goto b ;
  182.     
  183.     if ( index.stopCase == typeNull )
  184.         {
  185.             dWhoseRange = dRangeStart ;
  186.             dRangeStart.dataHandle = NULL ;            /* so we don't double dispose */
  187.             dWhoseRangeRec.dataHandle = NULL ;
  188.         }
  189.     else
  190.         {
  191.             err = AECreateList( NULL, 0, true, &dWhoseRangeRec ) ;
  192.             if ( err != noErr ) goto c ;
  193.  
  194.             err = AEPutKeyPtr( &dWhoseRangeRec, keyAEWhoseRangeStop, index.stopCase,
  195.                             (Ptr)&index.stopValue, sizeof(index.stopValue) ) ;
  196.             if ( err != noErr ) goto d ;
  197.  
  198.             err = AEPutKeyDesc( &dWhoseRangeRec, keyAEWhoseRangeStart, &dRangeStart ) ;
  199.             if ( err != noErr ) goto d ;
  200.  
  201.             err = AECoerceDesc( &dWhoseRangeRec, typeWhoseRange, &dWhoseRange) ;
  202.             if ( err != noErr ) goto d ;
  203.         } ;
  204.  
  205.     err = AEPutKeyDesc( &dWhoseRecord, keyAEIndex, &dWhoseRange ) ;
  206.     if ( err != noErr ) goto e ;
  207.     
  208.     err = AECoerceDesc( &dWhoseRecord, typeWhoseDescriptor, result ) ;
  209.  
  210. e:
  211.     IgnoreOSErr( AEDisposeDesc( &dWhoseRange ) ) ;
  212. d:
  213.     IgnoreOSErr( AEDisposeDesc( &dWhoseRangeRec ) ) ;
  214. c:
  215.     IgnoreOSErr( AEDisposeDesc( &dRangeStart ) ) ;
  216. b:
  217.     IgnoreOSErr( AEDisposeDesc( &dWhoseRecord ) ) ;
  218. a:
  219.     return err ;
  220. } // MakeExternalWhose
  221.  
  222.  
  223. //———————————————————————— iAESetObjectCallbacks ————————————————————————
  224. pascal OSErr
  225. iAESetObjectCallbacks( OSLCompareUPP myCompareProc, OSLCountUPP myCountProc,
  226.         OSLDisposeTokenUPP myDisposeTokenProc,
  227.         OSLGetMarkTokenUPP myGetMarkTokenProc, OSLMarkUPP myMarkProc,
  228.         OSLAdjustMarksUPP myAdjustMarksProc,
  229.         OSLGetErrDescUPP reserved )
  230.  
  231.         // changed model to allow nil procs; replace/enter iff non-nil
  232. {
  233.     OSErr out ;
  234.  
  235.     out = noErr ;
  236.  
  237.     if ( myCompareProc != NULL )
  238.         out = AEInstallSpecialHandler( keyAECompareProc,
  239.                 (UniversalProcPtr)myCompareProc, false ) ;
  240. //        ELSE
  241. //        out := errRequiredProcAbsent;
  242.  
  243.     if ( (out == noErr) && (myCountProc != NULL) )
  244.         out = AEInstallSpecialHandler( keyAECountProc, (UniversalProcPtr)myCountProc, false ) ;
  245. //        ELSE
  246. //        out := errRequiredProcAbsent; 
  247.  
  248.     // these procs are optional, so we are less upset about not seeing them        //<eeh> added first two
  249.     if ( (out == noErr) && (myDisposeTokenProc != NULL) )
  250.         out = AEInstallSpecialHandler( keyDisposeTokenProc,
  251.                 (UniversalProcPtr)myDisposeTokenProc, false);
  252.  
  253.     if ( (out == noErr) && (myGetMarkTokenProc != NULL) )
  254.         out = AEInstallSpecialHandler( keyAEMarkTokenProc,
  255.                 (UniversalProcPtr)myGetMarkTokenProc, false);
  256.     if ( (out == noErr) && (myMarkProc != NULL) )
  257.         out = AEInstallSpecialHandler(keyAEMarkProc,
  258.                 (UniversalProcPtr)myMarkProc, false);
  259.     if ( (out == noErr) && (myAdjustMarksProc != NULL) )
  260.         out = AEInstallSpecialHandler( keyAEAdjustMarksProc,
  261.                 (UniversalProcPtr)myAdjustMarksProc, false);
  262.  
  263.     if ( ( out == noErr ) && ( reserved != NULL ) )
  264.         out = AEInstallSpecialHandler( keyAEGetErrDescProc,
  265.                 (UniversalProcPtr)reserved, false ) ;
  266.  
  267.     return out;            // <eeh> in Pascal, this preceeded last if above
  268. } // iAESetObjectCallbacks
  269.  
  270.  
  271. #if 0
  272.     // Currently this routine does nothing...
  273.     
  274.     #ifndef __FRAGLOAD__
  275.     #include <FragLoad.h>
  276.     #endif
  277.     
  278.     #ifndef __MACRUNTIME__
  279.     #include <MacRuntime.h>
  280.     #endif
  281.     
  282.     #pragma lib_export on
  283.     
  284.     pascal OSErr OSLCFMInit (InitBlockPtr initBlkPtr)
  285.     {
  286.         return noErr;
  287.     }
  288.  
  289. #endif /*0*/